package com.leyou.item.mapper;

import com.leyou.item.pojo.Brand;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.additional.idlist.SelectByIdListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface BrandMapper extends Mapper<Brand>, SelectByIdListMapper<Brand,Long> {


    /**
     * 新增商品分类和品牌中间表数据
     * @param cid 商品分类id
     * @param bid    品牌id
     * @return
     */

    @Insert("INSERT INTO tb_category_brand (category_id,brand_id) VALUES (#{cid},#{bid})")
    void insertCategoryBrand(@Param("cid") Long cid, @Param("bid") Long bid);


//    @Update("UPDATE tb_category_brand SET category_id = #{cid} WHERE brand_id = #{bid}")
//    void updateCategoryBrand(@Param("cid") Long cid, @Param("bid") Long bid);


    @Delete("delete from tb_category_brand where brand_id = #{bid} ")
    void deleteCategoryBrand(@Param("bid") Long bid);


    @Select("SELECT b.* FROM tb_category_brand cb LEFT JOIN tb_brand b ON cb.brand_id = b.id WHERE cb.category_id = #{cid}")
    List<Brand> queryByCategoryId(Long cid);
}
